package com.chukun.disruptor;

import com.chukun.disruptor.netty.client.NettyClient;
import com.chukun.disruptor.netty.client.NettyClientConsumer;
import com.chukun.disruptor.netty.common.CommonConstants;
import com.chukun.disruptor.netty.disruptor.consumer.MessageConsumer;
import com.chukun.disruptor.netty.disruptor.factory.RingBufferWorkerPoolFactory;
import com.lmax.disruptor.BlockingWaitStrategy;
import com.lmax.disruptor.dsl.ProducerType;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * @author chukun
 * disruptor 客户端启动
 */
@SpringBootApplication
public class JavaDisruptorApplicationClient {

    public static void main(String[] args)  {
        SpringApplication.run(JavaDisruptorApplicationClient.class, args);
        //创建客户端消费者实例
        MessageConsumer[] clientConsumers = new NettyClientConsumer[5];

        for(int i=0;i<clientConsumers.length;i++){
            MessageConsumer  clientConsumer = new NettyClientConsumer("code:clientID: "+i);
            clientConsumers[i]=clientConsumer;
        }

        //启动客户端的disruptor
        RingBufferWorkerPoolFactory.getInstance().initAndStart(ProducerType.MULTI, CommonConstants.BUFFER_SIZE,new BlockingWaitStrategy(),clientConsumers);

//        new NettyServer();
        new NettyClient();
    }
}
